from django.contrib.contenttypes.models import ContentType
from django.db import models
from django.conf import settings
from apps.member.category.models import Category, Label
from apps.system.models import Upload


# Create your models here.

class Diary(models.Model):
    user = models.ForeignKey(settings.AUTH_USER_MODEL, verbose_name='作者', on_delete=models.PROTECT)
    title = models.CharField(verbose_name='标题', max_length=200)
    describe = models.CharField(verbose_name='描述', max_length=200)
    content = models.TextField(verbose_name='内容')
    image = models.ForeignKey(Upload, verbose_name='封面图', on_delete=models.PROTECT, null=True)
    category = models.ForeignKey(Category, verbose_name='分类', on_delete=models.PROTECT)
    label = models.CharField(verbose_name='标签', max_length=200, null=True)
    delete = models.BooleanField(verbose_name='删除', default=False)
    create_time = models.DateTimeField(verbose_name='创建时间', auto_now_add=True, editable=False)
    like_count = models.IntegerField(verbose_name='点赞', default=0)
    collect_count = models.IntegerField(verbose_name='收藏', default=0)
    browse_count = models.IntegerField(verbose_name='浏览量', default=0)

    @staticmethod
    def get_content_type():
        return ContentType.objects.get(model='Diary'.lower())

    class Meta:
        db_table = 'diary'
        verbose_name = '日记'
        default_permissions = ()

    def __str__(self):
        return self.title
